﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BUS;
using DTO;
namespace AirPlane
{
    public partial class DatVeB2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["islogin"] == null || (bool)Session["islogin"] == false || Session["type"].ToString() != "1")
            {

                Response.Redirect("TrangChu.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    txtNgaySinh.Text = "01/01/1990";
                    txtNgayHetHan.Text = DateTime.Now.ToShortDateString();
                    Session["khachHang"] = "";
                    if (Request["chuyenbaydi"].ToString() == "" || Request["hangvedi"].ToString() == "" || Request["sum"].ToString() == "" || Request["doiTuong"].ToString() == "")
                    {
                        Response.Redirect("DatVe.aspx");
                    }
                }
            }

        }

        protected void btnDatVeTiepTuc_Click(object sender, EventArgs e)
        {
            KhachHangDTO kh = new KhachHangDTO();
            KhachHangBUS bus = new KhachHangBUS();
            HoiVienBUS bus1 = new HoiVienBUS();
            DataTable dt = new DataTable();
            lbThongBao.Text = "";
          

            int flag = 0;
            lbThongBao.Text = "";
            kh.HoTen = txtHoTen.Text;
            kh.NgaySinh = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(txtNgaySinh.Text));
            kh.NgayHetHan = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(txtNgayHetHan.Text));
            kh.GioiTinh = bool.Parse(ddlGioiTinh.SelectedValue.ToString());
            kh.LoaiGiayTo = ddlGiayTo.SelectedValue.ToString();
            kh.SoThe = txtSoThe.Text;
            kh.NuocPhatHanh = ddlNuocPhatHanh.SelectedValue.ToString();
            kh.QuocTich = ddlQuocTich.SelectedValue.ToString();
            kh.MaHoiVien = txtSoTheHoiVien.Text;
            string soDienThoaiDiDong = txtSoDienThoai.Text;
            string soDienThoaiBan = txtSoDienThoaiBan.Text;
            if (soDienThoaiDiDong != "")
            {
                kh.SoDienThoaiDiDong = "(" + ddlMaQuocGia.SelectedValue.ToString() + ") - " + txtSoDienThoai.Text;
            }
            else
                kh.SoDienThoaiDiDong = "";
            if (soDienThoaiBan != "")
            {
                kh.SoDienThoaiBan = "(" + ddlMaQuocGia.SelectedValue.ToString() + ") - " + txtSoDienThoaiBan.Text;
            }
            else
                kh.SoDienThoaiBan = "";
            kh.Email = txtEmail.Text;

                   
            bool flag1 = true;
            if (txtSoTheHoiVien.Text != "")
                flag1 = bus1.kiemTraHoiVien(txtSoTheHoiVien.Text);
            if (flag1 == false)
                lbThongBao.Text = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Mã Hội Viên Này Chưa Đăng Ký</span>";
            else
            {
                lbThongBao.Text = "";
               // flag = bus.capNhatThongTin(kh);
                Session["khachHang"] = kh;
                string redirect = "DatVeB3.aspx?chuyenbaydi=" + Request["chuyenbaydi"].ToString();
                redirect += "&hangvedi=" +Request["hangvedi"].ToString();
                redirect += "&chuyenbayve=" + Request["chuyenbayve"].ToString();
                redirect += "&hangveve="+Request["hangveve"].ToString();
                redirect += "&sum=" + Request["sum"].ToString() + "&doiTuong=" + Request["doiTuong"].ToString();
                Response.Redirect(redirect);
            }

        }

        protected void btnHuyChuyenBay_Click(object sender, EventArgs e)
        {
            Response.Redirect("DatVe.aspx");
        }
    }
}